package com.idp.system.controller;

import com.idp.common.base.BaseController;
import com.idp.common.model.ResultModel;
import com.idp.system.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 共用Controller
 * @author king
 */
@Api(tags="共用")
@RestController
@RequestMapping("/common/")
public class CommonController extends BaseController {

	@Autowired
	private CommonService commonService;

	/**
	 * 文件显示
	 * @param id
	 * @param response
	 * @return
	 */
	@ApiOperation("文件显示")
	@GetMapping("showFile")
	public ResultModel showFile(@RequestParam("id") String id, HttpServletResponse response) {
		commonService.showFile(id, response);
		return ResultModel.success();
	}

	/**
	 * 文件上传
	 * @param file
	 * @param backType
	 * @return
	 */
	@ApiOperation("文件上传")
	@PostMapping("uploadFile")
	public ResultModel<String> uploadFile(MultipartFile file, String backType) {
		String url = commonService.uploadFile(file, backType);
		return ResultModel.success(url);
	}
}
